# coding: utf-8
from django.shortcuts import render_to_response, HttpResponse
from django.template import loader
import threading
from common.services.db import DBService



def z_render_to_response(template_name, context=None, content_type=None, status=None, using=None):
    """
    Returns a HttpResponse whose content is filled with the result of calling
    django.template.loader.render_to_string() with the passed arguments.
    """
    # ----------------add--------------
    context = context if context else {}

    current_thread = threading.currentThread()
    if hasattr(current_thread, 'z_user'):
        context.update({'z_user': current_thread.z_user})

    context.update({'activity_users_count': DBService.get_activity_users_count()})
    # print '----------c', context
    #-----------------end----------------

    content = loader.render_to_string(template_name, context, using=using)
    return HttpResponse(content, content_type, status)